package com.douhulu.bytedance.common.util.json;

import com.douhulu.bytedance.common.error.ByteError;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.util.Objects;

/**
 * <h2> 奕泽云 -  </h2>
 *
 * @Author: 奕泽云 - 曾庆雷
 * @Email: 75881401@qq.com
 * @Since: 2022-05-01 14:12
 * CopyRight：山西威斯汀文化传播有限公司
 */
public class ByteGsonBuilder {

    private static final GsonBuilder INSTANCE = new GsonBuilder();

    private static volatile Gson GSON_INSTANCE;

    static {
        INSTANCE.disableHtmlEscaping();
        //INSTANCE.registerTypeAdapter(OpenAccessToken.class, new OpenAccessTokenAdapter());
        INSTANCE.registerTypeAdapter(ByteError.class, new ByteErrorAdapter());
    }

    public static Gson create() {
        if (Objects.isNull(GSON_INSTANCE)) {
            synchronized (INSTANCE) {
                if (Objects.isNull(GSON_INSTANCE)) {
                    GSON_INSTANCE = INSTANCE.create();
                }
            }
        }
        return GSON_INSTANCE;
    }
}
